<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="org.apache.log4j.*"%>
<%@ page import="java.util.ResourceBundle"%>
<%@ page import="java.text.MessageFormat"%>
<%@ page import="java.util.Properties"%>
<%@ page import="java.io.File"%>
<%@ page import="java.io.InputStream"%>
<%@ page import="java.io.IOException"%>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*" %>
<%@ page import="com.adams.util.config.ConfigUtil" %>
<%@ page import="com.adams.config.engine.PropertesEngine"%>
<%@ page import="com.adams.common.ConfigVO"%>
<%
	Properties jdbcProperties = new Properties();
	Properties sysProperties = new Properties();
	String jdbcPropertiesName = "jdbc.properties";
	String jdbcFileDir = ConfigVO.class.getClassLoader().getResource("").getPath()+File.separator+jdbcPropertiesName;
	String sysPropertiesName = System.getProperty("os.name").toString().startsWith("Windows")?"win-sysconfig.properties":"linux-sysconfig.properties";
	String sysPropertiesDir = ConfigVO.class.getClassLoader().getResource("").getPath()+File.separator+"config"+File.separator+sysPropertiesName;
	jdbcProperties = ConfigUtil.loadProperties(jdbcPropertiesName,jdbcFileDir);
	sysProperties = ConfigUtil.loadProperties(sysPropertiesName,sysPropertiesDir);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>安装配置</title>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"/>
<link rel="Bookmark" href="images/favicon.ico" type="image/x-icon"/>
<style type="text">
	#wikibody{margin:1em 2em;padding:.25em;}
	#page,#wikibody.fav-right #favorites{float:right;}
</style>
<script type="text/javascript">
	//去两边空格   
    String.prototype.trim = function(){   
        return this.replace(/(^\s*)|(\s*$)/g, "");   
    };

	// 去空格; 
	function  trim(obj){
	  var value = obj.value.trim();
	  obj.value=value;
	} 
</script>
</head>
<body class="view">

<form name="configForm" action="Config.action" method="post">
<%
	String strConfig = (String)request.getAttribute("configed");
	if(strConfig==null){
%>


<table width="80%">
<tr>
	<td align="right">1</td>
	<td>
	<div class="vasmsconfigtitle">
		$JBOSS_HOME/server/default/deploy/adams.war/WEB-INF/classes/下找到jdbc.properties 文件
	</div>
	</td>
</tr>
	<%
	Enumeration<Object> enumsJdbc = jdbcProperties.keys(); 
	ConfigVO configVO = new ConfigVO();
	Iterator keys = configVO.getAdamsJdbcMap().keySet().iterator();
	while(keys.hasNext()){
		String key = (String)keys.next();
		String value = jdbcProperties.getProperty(key)==null?"":jdbcProperties.getProperty(key).toString();
			%>
			<tr align="center">
				<td align="right">
					<%=configVO.getAdamsJdbcMap().get(key) %>
				</td>
				<td align="left">
					<input type="text" name="<%=key %>" style="width:300px; height:20px;"  value="<%=request.getParameter(key)!=null?request.getParameter(key):ConfigVO.JDBC_URL_NAME.equals(key)?(value.substring(value.indexOf("//")>-1?value.indexOf("//")+2:0,value.indexOf("?")>-1?value.indexOf("?"):value.length())):value%>" onblur="trim(this)"/>
				</td>
			</tr>
			<%
	}
	%>
<tr>

	<td align="right">2</td>
	<td>
<div class="vasmssysconfig">在config目录下找到sysconfig.properties文件，根据服务器情况修改如下配制</div>
</td>

	</tr>
<%
	Enumeration<Object> enumsSys = sysProperties.keys(); 
	Iterator sysKeys = configVO.getAdamsSysMap().keySet().iterator();
	while(sysKeys.hasNext()){
		String key = (String)sysKeys.next();
		String value = sysProperties.getProperty(key)==null?"":sysProperties.getProperty(key).toString();
			%>
			<tr align="center">
				<td align="right">
					<%=configVO.getAdamsSysMap().get(key) %>
				</td>
				<td align="left">
					<input type="text" name="<%=key %>" style="width:300px; height:20px;"  value="<%=request.getParameter(key)!=null?request.getParameter(key):ConfigUtil.replaceSlash(sysProperties.getProperty(key))%>" onblur="trim(this)"/>
				</td>
			</tr>
			<%
	}
	%>
	<tr>
	<td></td>
	<td align="left">
		<input type="submit" name="submit" value="配置"/><Font color="#FF0000">${msg}</Font>
		</td>
		
	</tr>
</table>
<%}
	else{
		try{
			//Runtime.getRuntime().exec(serverDir);
			//serverDir = "E:\\apache-tomcat-6.0.14\\bin\\startup.bat";
			//Runtime.getRuntime().exec(serverDir);
			%>
			<p>配置成功，您需要重新启动服务器</p>
			<%
		}catch(Exception e){
			e.printStackTrace();
			%>
			<p>配置失败，失败原因</p>
			<%
		}
	}
%>
</form>
</body>
</html>
